<template>
  <div class="app-container">
    <!-- 查询和其他操作 -->
    <div class="filter-container">
      <el-select v-model="listQuery.storeId" placeholder="请选择门店名称">
        <el-option
          v-for="item in options"
          :key="item.storeId"
          :label="item.storeName"
          :value="item.storeId"
        >
        </el-option>
      </el-select>
      <el-select
        v-model="listQuery.type"
        placeholder="请选择类型"
        @change="changeType"
      >
        <el-option
          v-for="item in options2"
          :key="item.storeId"
          :label="item.name"
          :value="item.type"
        >
        </el-option>
      </el-select>
      <el-button
        class="filter-item"
        type="primary"
        icon="el-icon-search"
        @click="handleFilter"
        >查找</el-button
      >
      <!-- <el-button
        :loading="downloadLoading"
        class="filter-item"
        type="primary"
        icon="el-icon-download"
        @click="handleDownload"
      >导出</el-button>-->
    </div>

    <!-- 查询结果 -->
    <el-table
      v-loading="listLoading"
      :data="list"
      element-loading-text="正在查询中。。。"
      border
      fit
      highlight-current-row
    >
      <el-table-column
        align="center"
        :label="selectTimeType.name"
        :prop="selectTimeType.type == 'week' ? 'weekNum' : selectTimeType.type"
      />
      <el-table-column align="center" label="耗课统计" prop="countNum" />
    </el-table>
    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="listQuery.page"
      :limit.sync="listQuery.size"
      @pagination="getList"
    />
  </div>
</template>

<script>
import { getStoreLsit, getClassTimesCount } from '@/api/store/store'
import Pagination from '@/components/Pagination' // Secondary package based on el-pagination

export default {
  name: 'User',
  components: {
    Pagination,
  },
  data() {
    return {
      list: null,
      total: 0,
      listLoading: true,
      listQuery: {
        index: 0,
        size: 20,
        type: 'week',
        storeId: '',
      },
      options: [],
      options2: [
        {
          type: 'week',
          name: '周',
        },
        {
          type: 'month',
          name: '月',
        },
        {
          type: 'year',
          name: '年',
        },
      ],
      downloadLoading: false,
      genderDic: ['未知', '男', '女'],
      levelDic: ['普通用户', 'VIP用户', '高级VIP用户'],
      statusDic: ['启用', '禁用', '注销'],
      selectTimeType: {
        type: 'week',
        name: '周',
      },
    }
  },
  created() {
    this.getStoreLsitFun()
  },
  methods: {
    changeType(v) {
      const arr = this.options2.filter((item) => item.type == v)
      this.selectTimeType = arr[0]
      this.getList()
    },
    getStoreLsitFun() {
      getStoreLsit().then((response) => {
        this.options = response.data.data.content
        if (this.$route.query.storeId) {
          this.listQuery.storeId = Number(this.$route.query.storeId)
        }
        this.getList()
      })
    },
    getList(e) {
      if (e && e.page) {
        this.listQuery.index = e.page - 1
      }
      this.listLoading = true
      getClassTimesCount(this.listQuery)
        .then((response) => {
          this.list = response.data.data.content
          this.total = response.data.data.totalRecords
          this.listLoading = false
        })
        .catch(() => {
          this.list = []
          this.total = 0
          this.listLoading = false
        })
    },
    handleFilter() {
      this.listQuery.page = 0
      this.getList()
    },
    onEdit(data) {
      this.$router.push({
        name: 'editShop',
        query: {
          data: JSON.stringify(data),
        },
      })
    },
    onShowClass(data) {
      this.$router.push({
        name: 'classtimelist',
        query: {
          data: JSON.stringify(data),
        },
      })
    },
    handleSizeChange(v) {
      console.log(v)
      this.listQuery.size = v
    },
  },
}
</script>
